package com.tuling.jvm.classloader;

import java.net.URL;
import java.net.URLClassLoader;

/**
 * Created by chenhs on 2018/7/31.
 *
 * 测试一
 */
public class ClassLoaderTest {

    public static void main(String[] args) {

        try {
            /**
             * D:\studio\Java\jdk1.8.0_121\jre\lib\charsets.jar;D:\studio\Java\jdk1.8.0_121\jre\lib\deploy.jar;
             * D:\studio\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar;D:\studio\Java\jdk1.8.0_121\jre\lib\ext\cldrdata.jar;
             * D:\studio\Java\jdk1.8.0_121\jre\lib\ext\dnsns.jar;D:\studio\Java\jdk1.8.0_121\jre\lib\ext\jaccess.jar;
             * D:\studio\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar;D:\studio\Java\jdk1.8.0_121\jre\lib\ext\localedata.jar;
             * D:\studio\Java\jdk1.8.0_121\jre\lib\ext\nashorn.jar;D:\studio\Java\jdk1.8.0_121\jre\lib\ext\sunec.jar;
             * D:\studio\Java\jdk1.8.0_121\jre\lib\ext\sunjce_provider.jar;D:\studio\Java\jdk1.8.0_121\jre\lib\ext\sunmscapi.jar;
             * D:\studio\Java\jdk1.8.0_121\jre\lib\ext\sunpkcs11.jar;D:\studio\Java\jdk1.8.0_121\jre\lib\ext\zipfs.jar;
             * D:\studio\Java\jdk1.8.0_121\jre\lib\javaws.jar;D:\studio\Java\jdk1.8.0_121\jre\lib\jce.jar;
             * D:\studio\Java\jdk1.8.0_121\jre\lib\jfr.jar;D:\studio\Java\jdk1.8.0_121\jre\lib\jfxswt.jar;
             * D:\studio\Java\jdk1.8.0_121\jre\lib\jsse.jar;D:\studio\Java\jdk1.8.0_121\jre\lib\management-agent.jar;
             * D:\studio\Java\jdk1.8.0_121\jre\lib\plugin.jar;D:\studio\Java\jdk1.8.0_121\jre\lib\resources.jar;
             * D:\studio\Java\jdk1.8.0_121\jre\lib\rt.jar;D:\idea-workspace\tulinglog\target\classes;
             * D:\studio\m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;
             * D:\studio\m2\repository\org\slf4j\jcl-over-slf4j\1.7.25\jcl-over-slf4j-1.7.25.jar;
             * D:\studio\m2\repository\org\apache\logging\log4j\log4j-slf4j-impl\2.6.2\log4j-slf4j-impl-2.6.2.jar;
             * D:\studio\m2\repository\org\apache\logging\log4j\log4j-api\2.6.2\log4j-api-2.6.2.jar;
             * D:\studio\m2\repository\org\apache\logging\log4j\log4j-core\2.6.2\log4j-core-2.6.2.jar;
             * D:\studio\m2\repository\com\lmax\disruptor\3.0.1\disruptor-3.0.1.jar;
             * D:\studio\m2\repository\org\springframework\spring-context\4.2.6.RELEASE\spring-context-4.2.6.RELEASE.jar;
             * D:\studio\m2\repository\org\springframework\spring-aop\4.2.6.RELEASE\spring-aop-4.2.6.RELEASE.jar;
             * D:\studio\m2\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;
             * D:\studio\m2\repository\org\springframework\spring-beans\4.2.6.RELEASE\spring-beans-4.2.6.RELEASE.jar;
             * D:\studio\m2\repository\org\springframework\spring-core\4.2.6.RELEASE\spring-core-4.2.6.RELEASE.jar;
             * D:\studio\m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;
             * D:\studio\m2\repository\org\springframework\spring-expression\4.2.6.RELEASE\spring-expression-4.2.6.RELEASE.jar;
             * D:\studio\m2\repository\junit\junit\4.12\junit-4.12.jar;
             * D:\studio\m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;
             * D:\Program Files\JetBrains\IntelliJ IDEA 2017.1.4\lib\idea_rt.jar
             *
             * 查看当前系统类路径中包含的路径条目; 以上打印结果：
             */
            System.out.println(System.getProperty("java.class.path"));
            //System.out.println(System.getProperty("java.ext.dirs"));
            /**
             * 调用加载当前类的类加载器（这里即为系统类加载器）加载TestBean
             */
            Class typeLoaded = Class.forName("com.tuling.jvm.TestBean");
            /**
             * sun.misc.Launcher$AppClassLoader@18b4aac2
             * 查看被加载的TestBean类型是被哪个类加载器加载的; 以上打印结果：
             */
            System.out.println(typeLoaded.getClassLoader());

            //标准扩展类加载器能加载哪些路径下的类？
            try {
                URL[] extURLs = ((URLClassLoader) ClassLoader.getSystemClassLoader().getParent()).getURLs();
                for (int i = 0; i < extURLs.length; i++) {
                    System.out.println(extURLs[i]);
                }
            } catch (Exception e) {
                //…
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
